package net.zui.test;

import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.imageio.ImageIO;

import org.junit.Test;

import net.zui.util.UDraw;


public class TextClass1 {
	
	@Test
	public void test1() {
		BufferedImage img=new BufferedImage(640, 480, BufferedImage.TYPE_INT_ARGB);
		boolean alpha = UDraw.Alpha(img);
		System.out.println(alpha);
		Graphics2D g = (Graphics2D) img.getGraphics();
		g.setFont(new Font("宋体",Font.ITALIC+Font.BOLD,18));
		String str=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
		
		FontMetrics metrics = g.getFontMetrics();
		Rectangle2D bound = metrics.getStringBounds(str, g);
		
		g.setPaint(new Color(102,104,109,80));
		int height=0,cheight=(int) bound.getHeight();
		for(int i=0;i<img.getWidth(null);i+=20) {
			g.drawString(str,i, height);
			height+=cheight;
		}
		
		g.dispose();
		
		try {
			ImageIO.write(img, "PNG", new File("c:/1.png"));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
